﻿<?php
	defined('_JEXEC') or die(); 
    JHTML::_('behavior.tooltip'); 
?>
<style>
    #tbl_filter{
        margin: 0 ; padding: 0 ;
    }
    #tbl_filter td{
        padding: 3px;
    }
    #tbl_filter input, #tbl_filter img {
        float: left;
        margin: 0 5px 0 0;
        width: auto;
    }
    #extra_filter_field { width: 114px; }
    table.adminlist tbody tr td { padding: 8px 8px; }
    table.adminlist thead th { padding: 8px; }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery-ui.css" />
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.js"></script>
<script>
jQuery(function(){
		var status = <?php echo isset($this->status)?$this->status:2;?>;
		jQuery(".status").val(status);
		jQuery("#pick_up_at").multiselect({
            selectedList: 0,
            noneSelectedText: '-- All --',
            selectedText: "# of # selected"
        });
		
		jQuery("#topDisplaySelect").change(function(){
			jQuery("#topDisplay").val(jQuery(this).val());
			jQuery("#limit").val(jQuery(this).val());
			
			submitform();
			
		});
		var topDisplay = <?php echo empty($this->topDisplay)?20:$this->topDisplay;?>;
		
		jQuery("#topDisplaySelect").val(topDisplay);	
		
});
</script>
<div class="row-fluid">
    <?php if (!empty( $this->sidebar)) : ?>
	<div id="j-sidebar-container" class="span2">
		<?php echo $this->sidebar; ?>
	</div>
	<div id="j-main-container" class="span10">
	<?php else : ?>
		<div id="j-main-container">
	<?php endif;?>
		<br clear="all">	
    	<div class="alert">
             <form action="<?php echo JRoute::_("index.php?option=com_wrd&controller=reports")?>" method="post" name="filterform" >
                <table style='margin-bottom:5px' id="tbl_filter">
                    <tbody>
                        <tr>
                            <td align="left" valign="top" style="">
                                <table >
                                    <tr>
                                        <td valign="top">Status:<br>
                                            <select class="status" name="status" id="status">
												<option value="1">Used Voucher</option>
												<option value="-1">All</option>
												<option value="0">Unused voucher</option>
												<option value="9">Cancel Voucher</option>
                                            </select>
                                        </td>
									  
                                        <td>Voucher used, From:<br>
                                            <?php
												echo JHTML::_ ( 'calendar', $this->pr['date_from'], 'date_from', 'date_from', '%Y-%m-%d');
                                            ?>
                                            <br>To:<br>
                                            <?php
												echo JHTML::_ ( 'calendar', $this->pr['date_to'], 'date_to', 'date_to', '%Y-%m-%d');
                                            ?>
                                        </td>
										<td>Redemption from:<br>
                                            <?php
                                                echo JHTML::_ ( 'calendar', $this->pr['date_from_redem'], 'date_from_redem', 'date_from_redem', '%Y-%m-%d');
                                            ?>
                                            <br>To:<br>
                                            <?php
                                                echo JHTML::_ ( 'calendar', $this->pr['date_to_redem'], 'date_to_redem', 'date_to_redem', '%Y-%m-%d');
                                            ?>
                                        </td>
                                        <td>Outlet:<br>
                                            <?php echo $this->lists['filter_pick_up_outlet'] ; ?>
											
											
                                        </td>
										
                                    </tr>
                                </table>                                
                            </td>                             
                           
                    </tr>
                    <tr>
                    	<td>
                    		Choose: <br>
                                           <select class="topDisplay" name="topDisplaySelect" id="topDisplaySelect">
                                                <option value="5">5</option>
												<option value="10">10</option>
												<option value="15">15</option>
												<option value="20">20</option>
                                                <option value="30">30</option>
                                                <option value="50">50</option>
                                                <option value="100">100</option>
                                                <option value="">All</option>
                                            </select>
                                            <br>
							<input type="submit" name="view" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';  document.getElementById('task').value = 'redemptionreportvoucher';" value="View" />	
							<input type="submit" name="exportexcel" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';document.getElementById('task').value = 'exredempvoucher';" value="Export to excel" /></td>
						</td>
                    </tr>
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="submitViewExcel" id="submitViewExcel" value="" />
				<input type="hidden" name="task" id="task" value="" />
				</form>
			</div>
            <br />
<form id="adminForm" action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >			
<style>
.extra-adminlist strong { color:#025A8D; font-size: 1.2em; font-weight: bold; }
table.extra-adminlist .extra-adminlist-tr td {background: #F7F7F7; }
.filter-detail { border-top: 1px solid #CCC; padding-bottom: 3px; font-size: 1.4em; }
.filter-detail span { color: #e72222; }
</style>
<h3 class="filter-detail"><br/><span style="color:#C00; float:right;">Total: <?php echo $this->pagination->total; ?></span></h3>
<table class="adminlist extra-adminlist table">
  <thead>
    <tr class="extra-adminlist-tr" >
        <th nowrap="nowrap"><strong>No</strong></th>                   
		<th><strong>Item</strong></th>	
		<th><strong>Ngày Redemption</strong></th>	
		<th><strong>Redeemption Code</strong></th>
		<th><strong>Voucher Code</strong></th>	
		<th><strong>Expired Voucher</strong></th>			
		<th><strong>Date use voucher</strong></th>
		<th><strong>Outlet use voucher</strong></th>
		<th><strong>Name</strong></th>
		<th><strong>Point Redemp</strong></th>
		<th><strong>Cash Redemp</strong></th>
		<th><strong>Retail Pricing</strong></th>
		<th><strong>Cost Pricing</strong></th>
		<th><strong>Outlet</strong></th>
		<th><strong>Percent</strong></th>
		<th nowrap="nowrap"><strong>Charge Cost</strong></th>	
	    <th nowrap="nowrap"><strong>Status</strong></th> 
    </tr>
  </thead>
  <tbody>
    <?php 
        if(!empty($this->items)):
            $index = 0;
            $i=1;

			foreach($this->items as $key => $item):
            	$item->productName = unserialize($item->productName);
            	
				$item->productName = $item->productName['en-GB'];
               $bg = $i%2;
                echo '<tr style="cursor: pointer;" class="row'.($bg).'" valign="top">';
                    echo '<td  style="width: 5%;">'.$i.'</td>';   
					echo '<td  style="width:55%">'.$item->productName.'</td>'; 
					echo '<td  style="width:55%">'.$item->exchange_date.'</td>'; 
					echo '<td style="text-align:right;width:6%;">'.$item->code_redemption.'</td>';
					echo '<td style="text-align:right;width:6%;">'.$item->code_voucher.'</td>';
					echo '<td style="text-align:right;width:6%;">';
					echo empty($item->expired)? '':date("d-m-Y",strtotime($item->expired));
					echo '</td>';
					echo '<td style="text-align:right;width: 5%;">'.$item->date_voucher .'</td>';
					echo '<td style="text-align:right; width: 15%;">'.$item->outlet_name_use_voucher .'</td>';
					echo '<td style="text-align:right;width: 5%;"><a href="index.php?option=com_wrd&controller=profile&id='.$item->profile_id.'&layout=form" target="_blank">'.$item->l_name. " ".$item->f_name .'</a></td>';
					echo '<td style="text-align:right;width: 5%;">'.number_format($item->point,0,".",",") .'</td>';
					echo '<td style="text-align:right;width: 5%;">'.number_format($item->cash,0,".",",") .'</td>';
					echo '<td style="text-align:right;width: 5%;">'.number_format($item->product_cost,0,".",",") .'</td>';
					echo '<td style="text-align:right;width:5%;">'.number_format($item->cost_pricing,0,".",",") .'</td>';
					echo '<td style="text-align:right;width: 60%;">'.$item->outletName .'</td>';					
                    echo '<td style="text-align:right;">'.$item->percent.' %</td>';
					echo '<td style="text-align:right;">'.number_format($item->charge_cost,0,".",",").'</td>';
					echo '<td  style="width: 5%;">';
					if($item->status==0){
						echo "Unused Voucher";
					}
					elseif($item->status==1){ echo "Used Voucher";}
					elseif($item->status==9){echo "Cancel Voucher";}
					echo '</td>';
                echo '</tr>';
               $i++;
            endforeach;
        endif;
    ?>
  </tbody>
  <tfoot>
        <tr>
            <td colspan="16">
                <?php
                     echo $this->pagination->getListFooter();
                ?>
            </td>
        </tr>
    </tfoot>
</table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
				<input type="hidden" name="topDisplaySelect" id="topDisplay" value="" />
				<input name="status" type="hidden" class="status" value="" />
                <input type="hidden" name="task" value="redemptionreportvoucher" />
                <input type="hidden" name="boxchecked" value="0" />
                <?php echo JHTML::_( 'form.token' ); ?>
            </form>
        </div>
</div>
